package com.wang.spring.basic_dl.d_withannotation;

import com.wang.spring.basic_dl.d_withannotation.bean.Cat;
import com.wang.spring.basic_dl.d_withannotation.bean.Dog;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ImmediatlyLookupApplication {

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("basic_dl/quickstart-lazylookup.xml");
        Cat cat = context.getBean(Cat.class);
        System.out.println(cat);

        Dog dog;
        try {
            dog = context.getBean(Dog.class);
        } catch (NoSuchBeanDefinitionException e) {
            // 找不到Dog时手动创建
            dog = new Dog();
        }
        System.out.println(dog);
    }
}
